const url = ``;

function loadImg(src) {
  return new Promise((resolve, reject) => {
    const img = document.createElement("img");

    img.onload = () => {
      resolve(img);
    };

    img.onerror = () => {
      const err = new Error(`图片加载失败`);
      reject(err);
    };

    img.src = src;
  });
}

loadImg(url)
  .then((img) => {
    console.log(img.width);

    return img;
  })
  .then((img) => {
    console.log(img.height);
  })
  .catch((ex) => {
    console.log(ex);
  });
